<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>layui</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link rel="stylesheet" href="__PUBLIC__/layui/css/layui.css"  media="all">
    <!-- 注意：如果你直接复制所有代码到本地，上述css路径需要改成你本地的 -->
</head>
<body style="padding:15px;">
<form class="layui-form" action="">
    <div class="layui-form-item">
        <label class="layui-form-label">排序</label>
        <div class="layui-input-block">
            <input type="text" name="order_num" lay-verify="title" autocomplete="off" placeholder="数字大的优先显示" class="layui-input" value="{$vo.order_num}">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">分类图片</label>
        <div class="layui-input-block">
            <div class="layui-upload">
                <button type="button" class="layui-btn layui-btn-danger" id="test1"><i class="layui-icon"></i>上传图片</button>
                <div class="layui-upload-list">
                    <img class="layui-upload-img layui-nav-img" id="demo1" src="{$vo.img}" style="width: 60px; height: 60px;<if condition="!$vo['img']">display: none;</if>">
                    <p id="demoText"></p>
                </div>
            </div>
            <input type="hidden" id="imgurl" name="img" value="{$vo.img}">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">跳转位置</label>
        <div class="layui-input-block" style="padding-top: 9px;color: blue;">
            <text>积分商品</text>
        </div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label">选择商品</label>
        <div class="formControls layui-input-block">
            <select class="select" name="goods_id" style="height: 31px;" lay-search="">
                <option value="" selected>输入关键字搜索 或 选择商品</option>
                <foreach name="goods" item="v">
                    <option value="{$v.id}" <if condition="$vo['goods_id'] == $v['id']">selected</if>>{$v.name}</option>
                </foreach>
            </select>
        </div>
    </div>


    <input type="hidden" id="" name="id" value="{$vo.id}">
    <div class="layui-form-item">
        <div class="layui-input-block">
            <button class="layui-btn" lay-submit="" lay-filter="*">立即提交</button>
            <button type="reset" class="layui-btn layui-btn-primary">重置</button>
        </div>
    </div>
</form>

<script src="__PUBLIC__/layui/layui.js" charset="utf-8"></script>
<!-- 注意：如果你直接复制所有代码到本地，上述js路径需要改成你本地的 -->
<script>
    layui.use(['form','upload'], function(){
        var form = layui.form
                ,layer = layui.layer
                ,$ = layui.jquery
                ,upload = layui.upload;


        var uploadInst = upload.render({
            elem: '#test1'
            ,url: '{:U("Home/Public/upload")}'
            ,before: function(obj){
                //预读本地文件示例，不支持ie8
                obj.preview(function(index, file, result){
                    $('#demo1').attr('src', result).show(); //图片链接（base64）
                });
            }
            ,done: function(res){
                //如果上传失败
                if(res.err_code > 0){
                    return layer.msg('上传失败');
                }else{
                    $("#imgurl").val("https://www.58zltc.com/Uploads/"+res.file_name);
                }
                //上传成功
            }
            ,error: function(){
                //演示失败状态，并实现重传
                var demoText = $('#demoText');
                demoText.html('<span style="color: #FF5722;">上传失败</span> <a class="layui-btn layui-btn-mini demo-reload">重试</a>');
                demoText.find('.demo-reload').on('click', function(){
                    uploadInst.upload();
                });
            }
        });
        //监听提交
        form.on('submit(*)', function(data){
            $.post('#', data.field, function(e) {
                layer.alert(e.info,function(index){
                    parent.location.reload();
                });
            });
            return false;
        });

        $('#do_search').click(function(e){
            var keyword = $('.search_text').val();
            if(keyword == ''){
                layer.msg('关键字不能为空');
                return false;
            }
            var box =$('#search-item');
            var jump_type = $('input[name="type"]:checked').val();
            $("select[name='search_id']").empty();
            $.ajax({
                type:"GET",
                url:"{:U('search')}?keyword="+keyword+"&type="+jump_type,
                dataType:"json",
                contentType: "application/x-www-form-urlencoded; charset=utf-8",
                success:function(res){

//                      $('#select_search').append(res);
//                      $(".search_option").show();
                    $.each(res,function(k,v){
                        var i = "{src:'" +v.img_url +"', css:'height:40px;width:40px;'}";
                        var l = "<option lay-filter='osearch' value=" + v.id +" img="+'"'+""+i+""+'"'+">"
                                +v.title
                                +"</option>";
                        $('#select_search').append(l);


                    });
                    form.render('select');
                    $(".search_option").show();
                }
            })
        });


    });
</script>

</body>
</html>